/**
 */
package org.mro.grib.model.files.firstEdition.sections.impl;

import java.nio.ByteBuffer;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.EObjectImpl;
import org.mro.grib.core.GribException;
import org.mro.grib.model.files.firstEdition.sections.GridDefinitionSection;
import org.mro.grib.model.files.firstEdition.sections.SectionsPackage;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Grid Definition Section</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link org.mro.grib.model.files.firstEdition.sections.impl.GridDefinitionSectionImpl#getStartOffset <em>Start Offset</em>}</li>
 *   <li>{@link org.mro.grib.model.files.firstEdition.sections.impl.GridDefinitionSectionImpl#getEndOffset <em>End Offset</em>}</li>
 *   <li>{@link org.mro.grib.model.files.firstEdition.sections.impl.GridDefinitionSectionImpl#getLength <em>Length</em>}</li>
 *   <li>{@link org.mro.grib.model.files.firstEdition.sections.impl.GridDefinitionSectionImpl#getNv <em>Nv</em>}</li>
 *   <li>{@link org.mro.grib.model.files.firstEdition.sections.impl.GridDefinitionSectionImpl#getPvOffset <em>Pv Offset</em>}</li>
 *   <li>{@link org.mro.grib.model.files.firstEdition.sections.impl.GridDefinitionSectionImpl#getPlOffset <em>Pl Offset</em>}</li>
 *   <li>{@link org.mro.grib.model.files.firstEdition.sections.impl.GridDefinitionSectionImpl#getDataRepresentationType <em>Data Representation Type</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class GridDefinitionSectionImpl extends EObjectImpl implements GridDefinitionSection {
	/**
	 * The default value of the '{@link #getStartOffset() <em>Start Offset</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getStartOffset()
	 * @generated
	 * @ordered
	 */
	protected static final long START_OFFSET_EDEFAULT = 0L;

	/**
	 * The cached value of the '{@link #getStartOffset() <em>Start Offset</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getStartOffset()
	 * @generated
	 * @ordered
	 */
	protected long startOffset = START_OFFSET_EDEFAULT;

	/**
	 * The default value of the '{@link #getEndOffset() <em>End Offset</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getEndOffset()
	 * @generated
	 * @ordered
	 */
	protected static final long END_OFFSET_EDEFAULT = 0L;

	/**
	 * The cached value of the '{@link #getEndOffset() <em>End Offset</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getEndOffset()
	 * @generated
	 * @ordered
	 */
	protected long endOffset = END_OFFSET_EDEFAULT;

	/**
	 * The default value of the '{@link #getLength() <em>Length</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getLength()
	 * @generated
	 * @ordered
	 */
	protected static final int LENGTH_EDEFAULT = 0;

	/**
	 * The cached value of the '{@link #getLength() <em>Length</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getLength()
	 * @generated
	 * @ordered
	 */
	protected int length = LENGTH_EDEFAULT;

	/**
	 * The default value of the '{@link #getNv() <em>Nv</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getNv()
	 * @generated
	 * @ordered
	 */
	protected static final byte NV_EDEFAULT = 0x00;

	/**
	 * The cached value of the '{@link #getNv() <em>Nv</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getNv()
	 * @generated
	 * @ordered
	 */
	protected byte nv = NV_EDEFAULT;

	/**
	 * The default value of the '{@link #getPvOffset() <em>Pv Offset</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getPvOffset()
	 * @generated
	 * @ordered
	 */
	protected static final byte PV_OFFSET_EDEFAULT = 0x00;

	/**
	 * The cached value of the '{@link #getPvOffset() <em>Pv Offset</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getPvOffset()
	 * @generated
	 * @ordered
	 */
	protected byte pvOffset = PV_OFFSET_EDEFAULT;

	/**
	 * The default value of the '{@link #getPlOffset() <em>Pl Offset</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getPlOffset()
	 * @generated
	 * @ordered
	 */
	protected static final byte PL_OFFSET_EDEFAULT = 0x00;

	/**
	 * The cached value of the '{@link #getPlOffset() <em>Pl Offset</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getPlOffset()
	 * @generated
	 * @ordered
	 */
	protected byte plOffset = PL_OFFSET_EDEFAULT;

	/**
	 * The default value of the '{@link #getDataRepresentationType() <em>Data Representation Type</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getDataRepresentationType()
	 * @generated
	 * @ordered
	 */
	protected static final byte DATA_REPRESENTATION_TYPE_EDEFAULT = 0x00;

	/**
	 * The cached value of the '{@link #getDataRepresentationType() <em>Data Representation Type</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getDataRepresentationType()
	 * @generated
	 * @ordered
	 */
	protected byte dataRepresentationType = DATA_REPRESENTATION_TYPE_EDEFAULT;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected GridDefinitionSectionImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return SectionsPackage.Literals.GRID_DEFINITION_SECTION;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public long getStartOffset() {
		return startOffset;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setStartOffset(long newStartOffset) {
		long oldStartOffset = startOffset;
		startOffset = newStartOffset;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, SectionsPackage.GRID_DEFINITION_SECTION__START_OFFSET, oldStartOffset, startOffset));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public long getEndOffset() {
		return endOffset;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setEndOffset(long newEndOffset) {
		long oldEndOffset = endOffset;
		endOffset = newEndOffset;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, SectionsPackage.GRID_DEFINITION_SECTION__END_OFFSET, oldEndOffset, endOffset));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public int getLength() {
		return length;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setLength(int newLength) {
		int oldLength = length;
		length = newLength;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, SectionsPackage.GRID_DEFINITION_SECTION__LENGTH, oldLength, length));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public byte getNv() {
		return nv;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setNv(byte newNv) {
		byte oldNv = nv;
		nv = newNv;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, SectionsPackage.GRID_DEFINITION_SECTION__NV, oldNv, nv));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public byte getPvOffset() {
		return pvOffset;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setPvOffset(byte newPvOffset) {
		byte oldPvOffset = pvOffset;
		pvOffset = newPvOffset;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, SectionsPackage.GRID_DEFINITION_SECTION__PV_OFFSET, oldPvOffset, pvOffset));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public byte getPlOffset() {
		return plOffset;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setPlOffset(byte newPlOffset) {
		byte oldPlOffset = plOffset;
		plOffset = newPlOffset;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, SectionsPackage.GRID_DEFINITION_SECTION__PL_OFFSET, oldPlOffset, plOffset));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public byte getDataRepresentationType() {
		return dataRepresentationType;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setDataRepresentationType(byte newDataRepresentationType) {
		byte oldDataRepresentationType = dataRepresentationType;
		dataRepresentationType = newDataRepresentationType;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, SectionsPackage.GRID_DEFINITION_SECTION__DATA_REPRESENTATION_TYPE, oldDataRepresentationType, dataRepresentationType));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case SectionsPackage.GRID_DEFINITION_SECTION__START_OFFSET:
				return getStartOffset();
			case SectionsPackage.GRID_DEFINITION_SECTION__END_OFFSET:
				return getEndOffset();
			case SectionsPackage.GRID_DEFINITION_SECTION__LENGTH:
				return getLength();
			case SectionsPackage.GRID_DEFINITION_SECTION__NV:
				return getNv();
			case SectionsPackage.GRID_DEFINITION_SECTION__PV_OFFSET:
				return getPvOffset();
			case SectionsPackage.GRID_DEFINITION_SECTION__PL_OFFSET:
				return getPlOffset();
			case SectionsPackage.GRID_DEFINITION_SECTION__DATA_REPRESENTATION_TYPE:
				return getDataRepresentationType();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case SectionsPackage.GRID_DEFINITION_SECTION__START_OFFSET:
				setStartOffset((Long)newValue);
				return;
			case SectionsPackage.GRID_DEFINITION_SECTION__END_OFFSET:
				setEndOffset((Long)newValue);
				return;
			case SectionsPackage.GRID_DEFINITION_SECTION__LENGTH:
				setLength((Integer)newValue);
				return;
			case SectionsPackage.GRID_DEFINITION_SECTION__NV:
				setNv((Byte)newValue);
				return;
			case SectionsPackage.GRID_DEFINITION_SECTION__PV_OFFSET:
				setPvOffset((Byte)newValue);
				return;
			case SectionsPackage.GRID_DEFINITION_SECTION__PL_OFFSET:
				setPlOffset((Byte)newValue);
				return;
			case SectionsPackage.GRID_DEFINITION_SECTION__DATA_REPRESENTATION_TYPE:
				setDataRepresentationType((Byte)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case SectionsPackage.GRID_DEFINITION_SECTION__START_OFFSET:
				setStartOffset(START_OFFSET_EDEFAULT);
				return;
			case SectionsPackage.GRID_DEFINITION_SECTION__END_OFFSET:
				setEndOffset(END_OFFSET_EDEFAULT);
				return;
			case SectionsPackage.GRID_DEFINITION_SECTION__LENGTH:
				setLength(LENGTH_EDEFAULT);
				return;
			case SectionsPackage.GRID_DEFINITION_SECTION__NV:
				setNv(NV_EDEFAULT);
				return;
			case SectionsPackage.GRID_DEFINITION_SECTION__PV_OFFSET:
				setPvOffset(PV_OFFSET_EDEFAULT);
				return;
			case SectionsPackage.GRID_DEFINITION_SECTION__PL_OFFSET:
				setPlOffset(PL_OFFSET_EDEFAULT);
				return;
			case SectionsPackage.GRID_DEFINITION_SECTION__DATA_REPRESENTATION_TYPE:
				setDataRepresentationType(DATA_REPRESENTATION_TYPE_EDEFAULT);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case SectionsPackage.GRID_DEFINITION_SECTION__START_OFFSET:
				return startOffset != START_OFFSET_EDEFAULT;
			case SectionsPackage.GRID_DEFINITION_SECTION__END_OFFSET:
				return endOffset != END_OFFSET_EDEFAULT;
			case SectionsPackage.GRID_DEFINITION_SECTION__LENGTH:
				return length != LENGTH_EDEFAULT;
			case SectionsPackage.GRID_DEFINITION_SECTION__NV:
				return nv != NV_EDEFAULT;
			case SectionsPackage.GRID_DEFINITION_SECTION__PV_OFFSET:
				return pvOffset != PV_OFFSET_EDEFAULT;
			case SectionsPackage.GRID_DEFINITION_SECTION__PL_OFFSET:
				return plOffset != PL_OFFSET_EDEFAULT;
			case SectionsPackage.GRID_DEFINITION_SECTION__DATA_REPRESENTATION_TYPE:
				return dataRepresentationType != DATA_REPRESENTATION_TYPE_EDEFAULT;
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (startOffset: "); //$NON-NLS-1$
		result.append(startOffset);
		result.append(", endOffset: "); //$NON-NLS-1$
		result.append(endOffset);
		result.append(", length: "); //$NON-NLS-1$
		result.append(length);
		result.append(", nv: "); //$NON-NLS-1$
		result.append(nv);
		result.append(", pvOffset: "); //$NON-NLS-1$
		result.append(pvOffset);
		result.append(", plOffset: "); //$NON-NLS-1$
		result.append(plOffset);
		result.append(", dataRepresentationType: "); //$NON-NLS-1$
		result.append(dataRepresentationType);
		result.append(')');
		return result.toString();
	}

	/* (non-Javadoc)
	 * @see org.mro.grib.model.files.firstEdition.sections.GridDefinitionSection#initialise(java.nio.ByteBuffer)
	 */
	@Override
	public void initialise(ByteBuffer buffer) throws GribException {
		nv = buffer.get();
		//pvOrPlLocation = buffer.get();
		dataRepresentationType = buffer.get();
		byte[] descriptionGrilleBinaire = new byte[buffer.array().length - buffer.position()];
		buffer.get(descriptionGrilleBinaire, 0, descriptionGrilleBinaire.length);
		//gridDescription = GrilleFactory.getInstance().createGridDescription(dataRepresentationType, descriptionGrilleBinaire);

	}
	
} //GridDefinitionSectionImpl
